home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
examples.arc
/
EXAMPL25.PRO
< prev
next >
Wrap
Text File
|
1986-10-07
|
1KB
|
38 lines
/* Program 25 */
/*
Running the goal:
intersect(X,[1,2,3],[2,3,4,5])
notice that four answers are returned. The
first one is complete and the remaining 3 are
subsets of the first. In tracing through the
program notice that once a solution has been
found, Turbo returns the value and then
begins backtracking to search for additional
solutions (see chapter 5: Turbo Prolog's
Relentless Search for Solutions). To stop
this back-tracking place a cut (!) at the end
of the second intersect() clause. Trace the
program now and see.
*/
domains
list = reference integer*
/*
Reference variables are discussed on page 149
*/
predicates
member(integer,list)
intersect(list,list,list)
clauses
member(X,[X|_]).
member(X,[_|Y]):- member(X,Y).
intersect([],[],_).
intersect([X|Y],[X|L1],L2):-
member(X,L2),
intersect(Y,L1,L2). /* cut (!) goes here */
intersect(Y,[_|L1],L2):-intersect(Y,L1,L2).